echo "Usage:openstack_install.sh <CONTROLLER IP> <GLANCE SERVER IP> <SERVICE NIC>"
echo "Are you specify controller IP($1)?"
echo "Are yor sure Glance IP($2)?"
echo "Are you sure SVC NIC($3)?"
echo "SVC NIC info"
echo "Desktop    : p1p1"
echo "Workstation: p4p1"
echo "Atom       : p2p2"
echo "ex) ./openstac_install.sh 192.168.1.224 192.168.1.223 p2p2"
echo "The number of arguments is: $#"

if [ $# -eq 3 ]
then
        echo "success"
else
        echo "fail"
        exit
fi

echo "going..."


sleep 5


msg="s/%SERVER%/$1/g"
msg2="s/%GLANCE_SERVER%/$2/g"

function install_package()
{
	apt-get update
	apt-get -y install qemu-system-x86
	apt-get -y install xtightvncviewer
	apt-get -y install nova-compute-kvm
	apt-get -y install neutron-plugin-openvswitch-agent
}

# $1: src file
# $2, dst file
# $3, url
function update_file()
{
	echo "Removing ... $1"
	rm -f $1
	echo "Update $1 from $2$3"
	wget -O $1 $2$3
}

install_package

NEUTRON_CONF=/etc/neutron/neutron.conf
NEUTRON_SRC=/etc/neutron/neutron.conf.compute
ML2=/etc/neutron/plugins/ml2/ml2_conf.ini
ML2_SRC=/etc/neutron/plugins/ml2/ml2_conf.ini.compute
URL=https://conf.googlecode.com/svn/trunk/openstack/icehouse

NOVA_CONF=/etc/nova/nova.conf
NOVA_SRC=/etc/nova/nova.conf.compute

update_file $NEUTRON_CONF $URL $NEUTRON_SRC
update_file $ML2 $URL $ML2_SRC
update_file $NOVA_CONF $URL $NOVA_SRC

sed -i $msg $NOVA_CONF
sed -i $msg2 $NOVA_CONF
sed -i $msg $NEUTRON_CONF
sed -i $msg $ML2

service nova-compute restart
service openvswitch-switch restart
service neutron-plugin-openvswitch-agent restart

echo "Add physical port to br-int"
